package reflect;

import java.io.InputStream;
import java.lang.reflect.Constructor;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.Scanner;
import java.util.Vector;
import java.util.stream.IntStream;
import java.util.stream.Stream;

public class ReflectDemo2 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入类：");
        String className = scanner.nextLine();
        try {
            Class cls = Class.forName(className);
            Object o = cls.newInstance();
            System.out.println(o);
            Constructor constructor = cls.getConstructor();
            Object o1 = constructor.newInstance();
            System.out.println(o1);
            constructor = cls.getConstructor(String.class);
            o1 = constructor.newInstance("张三");
            System.out.println(o1);
            constructor = cls.getConstructor(String.class,int.class);
            o1 = constructor.newInstance("李四",23);
            System.out.println(o1);
        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}
